<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Vote\Controller;

use Think\Controller;

class AppapplyController extends Controller {

    public function _initialize() {

        $apply = array(
            "title" => '万元加冕，现金等你拿！', //转发标题
            "desc" => '江苏绿地会App预上线，开始征名啦！参与即有奖，选用更有万元现金拿。快来加入吧！', //转发内容
            "link" => 'http://ldh.mo2.cn/vote.php/Appapply/loadInit/',
            "imgUrl" => C('IMG_PATH') . 'uploads/appapply.jpg',
            'acid' => 'apply'
        );
        $this->assign('sharePackage', json_encode($apply));
        $this->assign('signPackage', json_encode(getSignPackage()));
    }

    function index() {
        redirect(__APP__ . '/Appapply/loadInit/');
    }

    function loadInit() {
        $openid = wx_openid();
        $model = new \Vote\Model\AppapplyModel();
        $rs = $model->checkApply($openid);
        if ($rs) {
            redirect(__APP__ . '/Appapply/applyInfo?id=' . $rs['id']);
        } else {
            $this->assign('openid', $openid);
            $this->display('index');
        }
    }

    function applyInfo() {
        $id = intval($_REQUEST['id']);
        $model = new \Vote\Model\AppapplyModel();
        //print_r($model->getApplyInfById($id));exit;
        $this->assign('info', $model->getApplyInfById($id));
        $this->display('success');
    }

    function ajaxInsert() {
        $model = new \Vote\Model\AppapplyModel();
        $huiyuan = check_vip($_REQUEST['openid']);
        $data = array(
            'app_name' => $_REQUEST['app_name'],
            'app_info' => $_REQUEST['app_info'],
            'openid' => $_REQUEST['openid'],
            'huiyuan_tel' => $huiyuan['huiyuan_tel'],
            'ctime' => date('Y-m-d H:i:s')
        );
        return $model->insert($huiyuan['card_no'], $data);
    }

    //分项计量
    function sharelog() {
        $arr = array(
            'open_id' => $_REQUEST['openid'],
            'sharelink' => $_REQUEST['sharelink'],
            'activity_id' => 'appapply',
            'ctime' => time(),
            'utime' => time(),
        );
        M('sharelog')->add($arr);
    }

}
